package lol.oxguy3.androidball;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.*;


public class DrawView extends View implements OnTouchListener {
	public ColorBall cb1, cb2, cb3;
	//public ColorBall[] balls;
	Paint paint;
	int rainbowcount;
	
	public DrawView(Context c) {
		super(c);
		cb1 = new ColorBall(c, 10, 10);
		cb2 = new ColorBall(c, 10, 10);
		cb3 = new ColorBall(c, 10, 10);
		setFocusableInTouchMode(true);
		setOnTouchListener(this);
	}
	
	@Override
	protected void onDraw(Canvas cvs) {
		
		int ballcolor = 0xffffffff;
		int bgcolor = 0xff000000;
		
		switch (rainbowcount % 6) {
		case 0:
			ballcolor=0xffbb3333;
			break;
		case 1:
			ballcolor=0xffbbbb00;
			break;
		case 2:
			ballcolor=0xff33bb33;
			break;
		case 3:
			ballcolor=0xff00bbbb;
			break;
		case 4:
			ballcolor=0xff3333bb;
			break;
		case 5:
			ballcolor=0xffbb00bb;
			break;
		}
		
		switch ((rainbowcount+3) % 6) {
		case 0:
			bgcolor=0xffbb3333;
			break;
		case 1:
			bgcolor=0xffbbbb00;
			break;
		case 2:
			bgcolor=0xff33bb33;
			break;
		case 3:
			bgcolor=0xff00bbbb;
			break;
		case 4:
			bgcolor=0xff3333bb;
			break;
		case 5:
			bgcolor=0xffbb00bb;
			break;
		}
		rainbowcount++;
		
		
		cvs.drawColor(bgcolor);
		//for (int i = 0; i<balls.length; i++) {}
		cb1.onMove(5, 5, cb1);
		paint = new Paint();
		
		paint.setColor(ballcolor);
		paint.setAntiAlias(true);
		cvs.drawCircle(cb1.getPosX(), cb1.getPosY(), 5, paint);
		invalidate();
	}

	public boolean onTouch(View v, MotionEvent event) {
		cb1.setPosX((int)event.getX());
		cb1.setPosY((int)event.getY());
		invalidate();
		
		return true;
	}
}
